<?php $this->load->view('templates/backend/header'); ?>
<?php if(!empty($lists)){ ?>
<style>
    .table .new,.notice{
        font-weight: bold;
        color:#D65824;
    }
    .table-bordered{
            border-top:1px solid #ccc;
    }
    .pagination {
        display: inline-block;
        padding-left: 0;
        margin: 20px 0;
        border-radius: 4px;
      }
      .pagination>li {
        display: inline;
      }
      .pagination>li>a, .pagination>li>span {
        position: relative;
        float: left;
        padding: 6px 12px;
        margin-left: -1px;
        line-height: 1.42857143;
        color: #337ab7;
        text-decoration: none;
        background-color: #fff;
        border: 1px solid #ddd;
      }
      .time{
          width:10%;
          
      }
      #submit,#export{vertical-align: top;}
</style>
<h3><?php echo $this->lang->line('listship_list');?></h3>
<!----filter box---->
<?php $this->load->view('auth/listship/filter'); ?>
<!----filter box---->
<table class="table table-striped table-bordered dataTable" id="data-table" width="100%" aria-describedby="data-table_info" style="width: 100%;">
    <thead>
        <tr role="row">
            <th width="5%" class="sorting_desc" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Username" style="width: 280px;"><?php echo $this->lang->line('phone');?></th>
            <th width="5%" class="sorting_desc" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Username" style="width: 280px;"><?php echo $this->lang->line('customersName');?></th>
            <th width="5%" class="sorting_desc" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Username" style="width: 280px;"><?php echo $this->lang->line('ship');?></th>
            <th width="5%" class="sorting_desc" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Username" style="width: 280px;"><?php echo $this->lang->line('saler');?></th>
            <th width="20%" class="sorting" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Code game" style="width: 181px;"><?php echo $this->lang->line('date_sale');?></th>
            <th width="20%" class="sorting" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Code game" style="width: 181px;"><?php echo $this->lang->line('status');?></th>
            <th width="20%" class="sorting" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Code game" style="width: 181px;"><?php echo $this->lang->line('note');?></th>
            <th width="20%" class="sorting" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Code game" style="width: 181px;"><?php echo $this->lang->line('booker');?></th>
            <th width="20%" class="sorting" role="columnheader" tabindex="0" aria-controls="data-table" rowspan="1" colspan="1" aria-label="Code game" style="width: 181px;"><?php echo $this->lang->line('action');?></th>
        </tr>
    </thead>

    <tbody role="alert" aria-live="polite" aria-relevant="all" id="lists">
        <?php
            foreach($lists AS $key => $value){
                if($key%2 == 0){
                    $old = 'new';
                } else {
                    $old = 'old';
                }
                switch ($value->phone_callstatus){
                    case '4':
                        $phone_callstatus   = $this->lang->line('phone_callok');
                        $assign             = '<a href="'.base_url().'auth/listship/assign?salesID='.$value->salesID.'&phone='.$value->phone.'" class="fancy-sl"><img src="'.STATIC_URL.'backend/images/icon/assign.png" /></a>';
                        break;
                    case '3':
                        $phone_callstatus   = $this->lang->line('phone_callback');
                        $assign             = '';
                        break;
                    default :
                        $phone_callstatus   = '';
                        $assign             = '';
                }
                if($value->booker){
                    $booker = $this->listship_model->getOwnerFromTblUser($value->booker);
                }
                if(!in_array($this->session->userdata['group_id'],array(76,1))){
                    $assign = "";
                }
                
                echo '<tr class="'.$old.'">';
                echo '<td class="">'.$value->phone.'</td>';
                echo '<td class="">'.$value->name.'</td>';
                echo '<td class="">'.$value->note_customers.'</td>';
                echo '<td class="">'.$value->saler.'</td>';
                echo '<td class="">'.date("d-m-Y H:i:s",$value->lastupdated).'</td>';
                echo '<td class="">'.$phone_callstatus.'</td>';
                echo '<td class="">'.$value->note.'</td>';
                echo '<td class="">'.$booker[0]->firstname.'</td>';
                echo '<td class=""><a href="'.base_url().'auth/listship/call?salesID='.$value->salesID.'&phone='.$value->phone.'" class="fancy-sl"><img src="'.STATIC_URL.'backend/images/icon/call.png" /></a> '.$assign.'</td>';
                echo '</tr>';
                unset($booker);
                unset($assign);
            }
        ?>
    </tbody>
</table>
<?php } else {
    echo "Không tìm thấy nội dung!!!";
} ?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="<?php echo STATIC_URL;?>/backend/css/jquery.fancybox.css">
<script type="text/javascript" src="<?php echo STATIC_URL;?>/backend/js/jquery.fancybox.js"></script>
<script>
(function($)
{
    $(document).ready(function()
    {
        $.ajaxSetup(
        {
            cache: false,
            beforeSend: function() {
                //$('#notice').hide();
                $('#lists').hide();
            },
            complete: function() {
                //$('#loading').hide();
                $('#lists').show();
            },
            success: function() {
                //$('#loading').hide();
                $('#lists').show();
            }
        });
        var $container = $("#lists");
            var refreshId = setInterval(function()
            {
                $container.load('load');
            }, 25000000);//28800000
    });
})(jQuery);

$(".fancy-sl").on('click',function(e){
    $.ajax({
        type        : "POST",
        cache       : false,
        url         : $(this).attr('href'),
        success: function(data) {
            $.fancybox(data, {
                margin		: 0,
                padding		: 0,
                maxWidth	: '480px',
                maxHeight	: '400px',
                fitToView	: false,
                width		: '100%',
                height		: '100%',
                autoSize	: false,
                closeClick	: false,
                openEffect	: 'none',
                closeEffect	: 'none',
                titleShow	: true,
                closeBtn	: false,
            }); // fancybox
        }
    });
    e.preventDefault();	//STOP default action
});

</script>
<?php 
    $this->load->view('templates/backend/footer'); 
    $this->load->view('templates/backend/datepicker'); 
?>
